package com.mall.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.exceotion.BusinessException;
import com.mall.commons.exceotion.ErrorResult;
import com.mall.commons.utils.PageUtils;
import com.mall.dubbo.api.OrderApi;
import com.tanhua.model.dto.OrderDto;
import com.tanhua.model.dto.OrderIdAllDto;
import com.tanhua.model.dto.ReceiverDto;
import com.tanhua.model.dto.UpdatedeliveryDto;
import com.tanhua.model.vo.PageVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @DubboReference
    private OrderApi orderApi;

    //查询订单
    public PageVo listOmsOrder(OrderDto orderDto) {
        Page page = orderApi.listOmsOrder(orderDto);
        PageVo pageDto = PageUtils.getPageVo(page);
        System.out.println(pageDto);
        pageDto.setPageSize(pageDto.getPageSize());
        // pageDto.setPageNum();
        return pageDto;
    }

    //获取订单详情：订单信息、商品信息、操作记录
    public OrderIdAllDto getById(Integer id) {
        OrderIdAllDto dto = orderApi.getById(id);
        if (dto == null) {
            throw new BusinessException(ErrorResult.emptyError());
        }
        return dto;
    }

/*    //批量发货
    public void upodates(OmsOrder omsOrder) {
        boolean exist = orderApi.upodates(omsOrder);

        if (!exist) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }*/

    //备注订单
    public void updateNote(Integer id, String note, Integer status) {
        boolean exist = orderApi.updateNote(id, note, status);

        if (!exist) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }

    //修改收货人信息
    public void updateReceiverInfo(ReceiverDto dto) {
        boolean exist = orderApi.updateReceiverInfo(dto);
        if (!exist) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }

    //批量发货
    public void updateDeliveryo(UpdatedeliveryDto[] dto) {
        boolean exist = orderApi.updateDeliveryo(dto);
        if (!exist) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }

    //批量删除订单
    public void deletesw(Integer[] ids) {
        boolean exist = orderApi.deletesw(ids);
        if (!exist) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }
}
